//
//  HYOUUserViewController.m
//  BestGift
//
//  Created by 温晓宇 on 15/12/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "HYOUUserViewController.h"
#import "HYOUUserView.h"
#import "HYOUSetUpViewController.h"
#import "UMSocial.h"
#import "HYOUWebViewController.h"
@interface HYOUUserViewController ()<HYOUUserView>

@property(nonatomic ,retain)HYOUUserView *uView;

@property(nonatomic, retain) NSMutableArray *array;

@end

@implementation HYOUUserViewController
-(void)viewWillAppear:(BOOL)animated{
    self.array = [NSMutableArray array];
    self.array = [[HYOUSingleton shareDataSingleton]selectHomeCell];
    self.uView.allArray = self.array;
    [self.uView.myTableView reloadData];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.uView = [[HYOUUserView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];

    [self.view addSubview:self.uView];
    self.uView.delegate = self;
    
//    NSUserDefaults *login = [NSUserDefaults standardUserDefaults];
//    [login setObject:@"no" forKey:@"login"];
    
//    [[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToSina  completion:^(UMSocialResponseEntity *response){
//        
//        UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
//        self.uView.url = snsAccount.iconURL;
//        self.uView.nameStr = snsAccount.userName;
//        NSLog(@"%@",snsAccount.iconURL);
//    }];
//    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 300, WIDTH, HEIGHT)];
//    [self.view addSubview:web];
//    NSURL *url = [NSURL URLWithString:@"http://www.liwushuo.com/posts/1028234/content"];
//    NSURLRequest *request = [NSURLRequest requestWithURL:url];
//    [web loadRequest:request];
    
//    [[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToSina  completion:^(UMSocialResponseEntity *response){
//        
//        UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
//        self.uView.url = snsAccount.iconURL;
//        self.uView.nameStr = snsAccount.userName;
//        NSLog(@"%@",snsAccount.iconURL);
//    }];
    
}
-(void)showCollecWeb:(NSString *)url{
    HYOUWebViewController *web = [[HYOUWebViewController alloc]init];
    web.url = url;
    [self.navigationController pushViewController:web animated:YES];
}
-(void)pushSetupView{
    HYOUSetUpViewController *setup = [[HYOUSetUpViewController alloc] init];
    [self.navigationController pushViewController:setup animated:YES];
}
-(void)loginView{
    
//    NSString *login = [[NSUserDefaults standardUserDefaults] objectForKey:@"login"];
//    if ([login isEqualToString:@"no"]) {
    
        UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
        
        snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
            
            //          获取微博用户名、uid、token等
            
            if (response.responseCode == UMSResponseCodeSuccess) {
                
                UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
                NSUserDefaults *login = [NSUserDefaults standardUserDefaults];
                [login setObject:@"yes" forKey:@"login"];

                NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
                
            }});
    [[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        
        UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
        self.uView.url = snsAccount.iconURL;
        self.uView.nameStr = snsAccount.userName;
        NSLog(@"%@",snsAccount.iconURL);
    }];
    

//    }else{
//       NSLog(@"您已登录");
//        
//    }
}

//-(void)logout{
//    if ([UMSocialAccountManager isLogin]) {
//        NSLog(@"未登录");
//    }else{
//        [[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina  completion:^(UMSocialResponseEntity *response){
//            NSLog(@"response is %@",response);
//            
//        }];
//    }
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
